const app = getApp();
const {upTime} = require('/util/public');
Page({
  data: {
    list:[],
    promoteId: '',
    promoteUserId: '',
    page: 0,
    rows: 20,
    loadingSta: 1,
    timer: '---- / -- / --'
  },
  onLoad() {
    console.log(111)
    this.getPromoteId();
  },


  // 加载
  lower(){
    this.promoteUserList();
  },


  // 获取推广员id
  getPromoteId(){
    let user = my.getStorageSync({ key: 'user' });
    let data = {
      list:[],
      promoteId: '',
      promoteUserId: '',
      page: 0,
      rows: 20,
      loadingSta: 1,
      timer: '---- / -- / --'
    }
    this.setData(data);

    if (user.data) {
        console.log("user", user)
        this.setData({
          promoteId: user.data.promoteId,
          promoteUserId: user.data.promoteUserId,
        })
        this.promoteUserList();
    } else {
        this.setData({
          promoteId: '',
          promoteUserId: '',
        })
    }
  },


  // 提现记录
  promoteUserList(){
    if(!this.data.promoteUserId){
      my.showToast({
        content:'未获取到推广员信息'
      })
      return;
    }

    let pages = this.data.page;
    pages += 1;

    let dat = {
      promoteAccountId: this.data.promoteUserId,
      // promoteAccountId: 72,
      page: pages,
      rows: this.data.rows
    }

    my.showLoading({
      content: '加载中...',
    });
    this.setData({
      loadingSta: 2,
    })

    app.user.promoteUserList(dat)
    .then(res=>{
      console.log(777,res);
      if(res.data && res.data.list.length > 0){

        let newList = this.data.list;

        this.setListType(res.data.list)
          .then(res=>{
            console.log(66666,res)
            newList.push(...res);

            this.setData({
              list: newList,
              page: pages,
              loadingSta: 1,
            })

          })

      }else{

        this.setData({
          loadingSta: 3,
        })

      }
      my.hideLoading();
    })
    .catch(err=>{
      my.hideLoading();
    })

  },

  setListType(list){
    return new Promise((relose, reject)=>{
      list.forEach((item) => {
        let timer = item.createtime.split(' ')[0];
        let timeArr = timer.split('-');
        item.createTimeStrFront = timeArr[0] + '.' + timeArr[1] + '.' + timeArr[2];
      })
      relose(list)
    })
  },



  // 跳转
  navigateTo(e){
    app.navigateTo(e)
  },



});
